package com.lagou.edu.minicat;

import com.lagou.edu.minicat.classloader.WebAppClassloader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;

public class ClassLoaderTest {

    public static void main(String[] args) throws ClassNotFoundException, MalformedURLException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        URL uri = new URL("file:/E:\\lagouworkspace\\lagou_edu_spring_hw\\lagou_edu_minicat\\webapps\\demo2\\WEB-INF\\classes");
        URL[] urls = {uri};
        WebAppClassloader classloader = new WebAppClassloader(urls);

        Class<?> aClass = classloader.loadClass("com.lagou.edu.minicat.LagouServlet");
        Servlet o = (Servlet) aClass.newInstance();
        o.destroy();

        URL url1 = new URL("file:/E:\\lagouworkspace\\lagou_edu_spring_hw\\lagou_edu_minicat\\webapps\\demo1\\WEB-INF\\classes");
        URL[] urls1 = {url1};
        WebAppClassloader classloader1 = new WebAppClassloader(urls1);
        Class<?> aClass1 = classloader1.loadClass("com.lagou.edu.minicat.LagouServlet");
        Object o1 = aClass1.newInstance();
        Servlet servlet = (Servlet)o1;
        servlet.init();
        Method destroy1 = o1.getClass().getMethod("destroy");
        destroy1.invoke(o1);
    }

}
